import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Window 2.0
import QtMultimedia 5.2
import DataMan 0.1
import "../utils.js" as Utils;
//import "../game.js" as Game;
import "../logic.js" as Logic;

ApplicationWindow {
	title: qsTr("5 Monsters")
	property Item runningScene: null

	visible: true
	width: 540
	height: 960
	//禁止改变窗口大小
	maximumWidth: width
	minimumWidth: width
	maximumHeight: height
	minimumHeight: height

	// 设定背景音乐播放器
	MediaPlayer {
		id: player
		source: "/sounds/BGM.ogg"
		loops: MediaPlayer.Infinite
	}

	onActiveChanged: {
		if (!DataMan.music) return;
		if (active) {
			player.play();
		} else {
			player.pause();
		}
	}

	function runScene(smakeCode)
	{
		if (runningScene)
			runningScene.destroy();
		runningScene = Qt.createQmlObject(smakeCode, Utils.AppWin);
	}

	Component.onCompleted:  {
		Utils.BGM = player;
		Utils.AppWin = this;
		Utils.DesiginScaleFactor.x = width / 480;
		Utils.DesiginScaleFactor.y = height / 800;
		// 从本地读取游戏矩阵和道具数量
		Logic.init({col:GameCol, row:GameRow, monstn:MonsterTypeN})
		Logic.syncData(true);
		runScene("MainScene{}");
	}
	onClosing: {
		// 写入游戏矩阵和道具数量
		Logic.syncData(false);
	}
}
